﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using NetJsWire.JsonRpcHandler;
using NetJsWire.JsonRpcHandler.Attributes;
using NetJsWire.JsonRpcHandler.Util;
using NetJsWire.Widgets.Config;
using NetJsWire.Widgets.Core;

namespace NetJsWire.Widgets.Data
{
    [Renderer( typeof( Renderers.Data.DirectStore ) )]
    public partial class DirectStore : Store, IDataStore
    {
        private readonly IRenderer _renderer;
        private IConfigOptions _configOptions;
        private string _directMethod;
        private string _idProperty;
        private string _root;
        private string _totalProperty;

        public DirectStore()
        {
            InitializeComponent();
            _renderer = Helper.GetRenderer( this );
        }

        public DirectStore( IContainer container )
        {
            container.Add( this );

            InitializeComponent();
            _renderer = Helper.GetRenderer( this );
        }

        public string DirectMethod
        {
            get { return _directMethod; }
            set
            {
                _directMethod = value;
                Renderer.SetConstructionProperty( "directFn", value );
            }
        }

        public string Root
        {
            get { return _root; }
            set
            {
                _root = value;
                Renderer.SetConstructionProperty( "root", value );
            }
        }

        public string IdProperty
        {
            get { return _idProperty; }
            set
            {
                _idProperty = value;
                Renderer.SetConstructionProperty( "idProperty", value );
            }
        }

        public string TotalProperty
        {
            get { return _totalProperty; }
            set
            {
                _totalProperty = value;
                Renderer.SetConstructionProperty( "totalProperty", value );
            }
        }

        [RefreshProperties( RefreshProperties.All ),
         DesignerSerializationVisibility( DesignerSerializationVisibility.Content ), Category( "Config" )]
        public override IConfigOptions ConfigOptions
        {
            get { return _configOptions ?? ( _configOptions = new StoreConfigOptions( this ) ); }
        }

        #region IDataStore Members

        [Browsable( false )]
        public override IRenderer Renderer
        {
            get { return _renderer; }
        }

        #endregion
    }
}
